//
//  UIView + Extension.swift
//  RongYiHua
//
//  Created by 卢小艳 on 2025/7/13.
//

import Foundation
import UIKit

extension UIView {

    /// 给 TextField 或 TextView 添加 “完成” 工具栏
    func jqfxhAddDoneButtoneeOnKeyboard(target: Any, action: Selector) {
        let toolbar = UIToolbar()
        toolbar.sizeToFit()

        let flexSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
        let doneButton = UIBarButtonItem(title: "完成", style: .done, target: target, action: action)

        toolbar.items = [flexSpace, doneButton]

        if let textField = self as? UITextField {
            textField.inputAccessoryView = toolbar
        } else if let textView = self as? UITextView {
            textView.inputAccessoryView = toolbar
        }
    }
}
